/*
 * @title: 底部菜单
 * @Description:
 * @Author: JZT.饶慧勇
 * @Date: 2025-05-30 13:45:01
 * @LastEditors: JZT.饶慧勇
 * @LastEditTime: 2025-05-30 15:08:50
 */

const tabbarItems = ref<ITabbarItem[]>([
  { path: '/pages/tabbar/home/index', value: null, active: true, title: 'Home', icon: 'home' },
  { path: '/pages/tabbar/my/index', value: null, active: false, title: 'My', icon: 'app' }
]);

export function useTabbar() {
  const tabbarList = computed(() => tabbarItems.value);

  const activeTabbar = computed(() => {
    const item = tabbarItems.value.find(item => item.active);
    return item || tabbarItems.value[0];
  });

  const getTabbarItemValue = (path: string) => {
    const item = tabbarItems.value.find(item => item.path === path);
    return item && item.value ? item.value : null;
  };

  const setTabbarItem = (path: string, value: number) => {
    const tabbarItem = tabbarItems.value.find(item => item.path === path);
    if (tabbarItem) {
      tabbarItem.value = value;
    }
  };

  const setTabbarItemActive = (path: string) => {
    tabbarItems.value.forEach(item => {
      if (item.path === path) {
        item.active = true;
      } else {
        item.active = false;
      }
    });
  };

  return {
    tabbarList,
    activeTabbar,
    getTabbarItemValue,
    setTabbarItem,
    setTabbarItemActive
  };
}
